﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Web.UI.WebControls;


namespace Admin72H.Controls.ProductPriceNews
{
    public partial class frmProductPriceNews : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!CommonWeb.CheckLogin())
            //    Response.Redirect("~/Login.aspx");

            //if (!IsPostBack)
            //{
            //    LoadProduct();
            //    LoadCity();
            //    LoadPriceType();
            //    LoadData();
            //}
        }

        private void LoadProduct()
        {
            //AMService.AMServiceClient AMServiceClient = CommonWeb.GetCurrent_AMService_Client();

            //var returnObject = AMServiceClient.GetListAllProduct();

            //if (returnObject.RetCode != (int)Common.CommonEnums.RetCode.SUCCESS)
            //    return;

            //ddlProduct.DataSource = returnObject.RetObject;
            //ddlProduct.DataTextField = "ProductName";
            //ddlProduct.DataValueField = "ProductId";
            //ddlProduct.DataBind();
        }

        private void LoadPriceType()
        {
            //AMService.AMServiceClient AMServiceClient = CommonWeb.GetCurrent_AMService_Client();

            //var returnObject = AMServiceClient.GetListAllPriceType();

            //if (returnObject.RetCode != (int)Common.CommonEnums.RetCode.SUCCESS)
            //    return;

            //ddlPriceType.DataSource = returnObject.RetObject;
            //ddlPriceType.DataTextField = "Name";
            //ddlPriceType.DataValueField = "Id";
            //ddlPriceType.DataBind();
        }

        private void LoadCity()
        {
            //AMService.AMServiceClient AMServiceClient = CommonWeb.GetCurrent_AMService_Client();

            //var returnObject = AMServiceClient.GetListAllCity();

            //if (returnObject.RetCode != (int)Common.CommonEnums.RetCode.SUCCESS)
            //    return;

            //ddlCity.DataSource = returnObject.RetObject;
            //ddlCity.DataTextField = "Name";
            //ddlCity.DataValueField = "Id";
            //ddlCity.DataBind();
        }

        void LoadData()
        {
            //string id = Request["ProductPriceNewsId"];
            //if (id == null)
            //{

            //}
            //else
            //{
            //    AMService.AMServiceClient AMServiceClient = CommonWeb.GetCurrent_AMService_Client();
            //    var returnObject = AMServiceClient.GetProductPriceNewsById(long.Parse(id));
            //    if (returnObject.RetCode != (int)Common.CommonEnums.RetCode.SUCCESS)
            //        return;
            //    else
            //    {
            //        var news = returnObject.RetObject;
            //        txtId.Text = news.Id.ToString();
            //        txtName.Text = news.Name;
            //        txtPrice.Text = news.Price.ToString("#");
            //        ddlProduct.SelectedValue = news.ProductId;
            //        ddlPriceType.SelectedValue = news.PriceTypeId.ToString();
            //        ddlCity.SelectedValue = news.CityId.ToString();
            //    }
            //}
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            //if (txtName.Text == "")
            //{
            //    lblStatus.Text = "Tên không được để trống!";
            //    return;
            //}

            //if (txtPrice.Text == "")
            //{
            //    lblStatus.Text = "Giá không được để trống!";
            //    return;
            //}

            //decimal price;
            //if (!decimal.TryParse(txtPrice.Text, out price))
            //{
            //    lblStatus.Text = "Giá không đúng định dạng!";
            //    return;
            //}

            //string id = Request["ProductPriceNewsId"];
            //if (id == null)
            //{
            //    AMService.AMServiceClient AMServiceClient = CommonWeb.GetCurrent_AMService_Client();
            //    int create = AMServiceClient.CreateProductPriceNews(ddlProduct.SelectedValue, txtName.Text, decimal.Parse(txtPrice.Text), int.Parse(ddlCity.SelectedValue), int.Parse(ddlPriceType.SelectedValue));
            //    if (create == (int)CommonEnums.RetCode.SUCCESS)
            //    {
            //        lblStatus.Text = "Thêm tin thành công!";
            //        hdModified.Value = "true";
            //    }
            //    else
            //        lblStatus.Text = "Thêm tin không thành công!";
            //}
            //else
            //{
            //    AMService.AMServiceClient AMServiceClient = CommonWeb.GetCurrent_AMService_Client();
            //    int update = AMServiceClient.UpdateProductPriceNews(long.Parse(txtId.Text), ddlProduct.SelectedValue, txtName.Text, decimal.Parse(txtPrice.Text), int.Parse(ddlCity.SelectedValue), int.Parse(ddlPriceType.SelectedValue));
            //    if (update == (int)CommonEnums.RetCode.SUCCESS)
            //    {
            //        lblStatus.Text = "Cập nhập tin thành công!";
            //        hdModified.Value = "true";
            //    }
            //    else
            //        lblStatus.Text = "Cập nhập tin không thành công!";
            //}
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            //txtName.Text = string.Empty;
            //txtPrice.Text = string.Empty;
            //ddlProduct.SelectedIndex = 0;
            //ddlPriceType.SelectedIndex = 0;
            //ddlCity.SelectedIndex = 0;
        }
    }
}
